package com.spzx.product.api;

import com.spzx.common.core.constant.SecurityConstants;
import com.spzx.common.core.constant.ServiceNameConstants;
import com.spzx.common.core.domain.R;
import com.spzx.product.api.factory.RemoteProductFallbackFactory;
import com.spzx.product.api.model.ProductSku;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestHeader;

//所有OpenFeign使用注解@FeignClient,被扫描产生代理对象,由代理对象使用RequestTemplate发起Http请求
//1.接口上配置信息得到请求地址: http://spzx-product/业务接口基础URL地址
//2.OpenFeign接口方法从controller复制而来 http://spzx-product/业务接口基础URL地址/getProductSku/{skuId}
//3.发送请求调用目标服务, 上游微服务会从Nacos根据服务名称"spzx-product"得到该服务下实例列表
//192.168.86.1:9205 和192.168.86.1:9105
//4.OpenFeign集成客户端(上游)负载均衡组件:  LoadBalancer组件默认轮巡策略
//5.请求1: http://192.168.86.1:9205/业务接口基础URL地址/getProductSku/{skuId}
//请求2: http://192.168.86.1:9105/业务接口基础URL地址/getProductSku/{skuId}
@FeignClient(value = ServiceNameConstants.PRODUCT_SERVICE,//请求哪个服务
                path="/productSku" //业务接口基础的URL地址
             ,fallbackFactory = RemoteProductFallbackFactory.class //服务降级的工厂 确保被IOC容器扫描注册对象
         )
public interface RemoteProductService {

    @Operation(summary = "获取商品SKU详情")
    @GetMapping("/getProductSku/{skuId}") //或者/productSku/getProductSku/{skuId}
    public R<ProductSku> getProductSku(@PathVariable("skuId") Long skuId
            , @RequestHeader(SecurityConstants.FROM_SOURCE) String source) ;

    }

